package app.ui;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;
import database.local.Comment;
import database.local.Utils;

public class CommentsListArrayAdapter extends BaseAdapter {
	
	private static List<Comment> commentsList;
	private LayoutInflater mInflater;
	
	public CommentsListArrayAdapter (Context context, List<Comment> results){
		commentsList = results;
		mInflater = LayoutInflater.from(context);
		
	}
	public int getCount() {
		return commentsList.size();
	}

	public Object getItem(int position) {
		return commentsList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		
		if (convertView == null){
			convertView = mInflater.inflate(R.layout.comment_row_layout, null);
			holder = new ViewHolder();
			
			holder.user = (TextView) convertView.findViewById(R.id.comment_row_user_Text);
			holder.date = (TextView) convertView.findViewById(R.id.comment_row_date_Text);
			holder.info = (TextView) convertView.findViewById(R.id.comment_row_info_Text);
			holder.rateBar = (RatingBar) convertView.findViewById(R.id.comment_row_rate_ratingbar);
			holder.moenyBar = (RatingBar) convertView.findViewById(R.id.comment_row_money_ratingbar);
			convertView.setTag(holder);
		}
		else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.user.setText(Utils.email_to_name(commentsList.get(position).getSource()));
		holder.date.setText(commentsList.get(position).getDate_time());
		holder.info.setText(commentsList.get(position).getComment_str());
		holder.rateBar.setRating(commentsList.get(position).getRate());
		holder.moenyBar.setRating(commentsList.get(position).getCost_level());
		return convertView;
	}
	static class ViewHolder {
		TextView user, date, info;
		RatingBar rateBar, moenyBar;
		
	}
}
